package com.ceshi.mvpdemo.View;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.ceshi.mvpdemo.Presenter.MvpPresenter;
import com.ceshi.mvpdemo.R;

public class MainActivity extends BaseActivity implements MvpView, View.OnClickListener {
    private TextView textView;
    private MvpPresenter mvpPresenter;
    private Button successbutton;
    private Button failurebutton;
    private Button errorbutton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mvpPresenter=new MvpPresenter();
        mvpPresenter.attachView(this);

        textView=findViewById(R.id.text_view);

        successbutton=findViewById(R.id.button_success);
        successbutton.setOnClickListener(this);

        failurebutton=findViewById(R.id.button_failure);
        failurebutton.setOnClickListener(this);

        errorbutton=findViewById(R.id.button_error);
        errorbutton.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_success:
                mvpPresenter.getData("normal");
                break;
            case R.id.button_failure:
                mvpPresenter.getData("failure");
                break;
            case R.id.button_error:
                mvpPresenter.getData("error");
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mvpPresenter.detachView();
    }

    @Override
    public void showData(String data) {
       textView.setText(data);
    }
}
